<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LINE 1 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-1"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span class="hs-comment">{- |
   Module      :  Graphics.Win32.GDI.AlphaBlend
   Copyright   :  2013 shelarcy
   License     :  BSD-style

   Maintainer  :  shelarcy@gmail.com
   Stability   :  Provisional
   Portability :  Non-portable (Win32 API)

   Provides alpha blending  functionality.
-}</span><span>
</span><span id="line-13"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Graphics.Win32.GDI.AlphaBlend</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Storable</span><span>         </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">Storable</span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Foreign.Ptr</span><span>              </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">Graphics.Win32.GDI.Types</span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">HDC</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">System.Win32.Types</span><span>       </span><span class="hs-special">(</span><span> </span><span class="hs-identifier">BOOL</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">BYTE</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">UINT</span><span> </span><span class="hs-special">)</span><span class="hs-cpp">



#include &quot;windows_cconv.h&quot;
</span><span>
</span><span id="line-23"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">ccall</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;alphablend.h&quot;</span><span>
</span><span id="line-24"></span><span>  </span><span class="hs-identifier">c_AlphaBlend</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HDC</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HDC</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">PBLENDFUNCTION</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-25"></span><span class="hs-comment">{-
We use C wrapper function to call this API.
Because foreign stacall/ccall/capi doesn't work with non-pointer user defined type.

We think that capi should support that when user defined type has Storable class instance
and using CTYPE pragma in the scope.

{-# LANGUAGE CApiFFI #-}

data {-# CTYPE &quot;windows.h&quot; &quot;BLENDFUNCTION&quot; #-} BLENDFUNCTION =

foreign import capi unsafe &quot;windows.h AlphaBlend&quot;
  c_AlphaBlend :: HDC -&gt; Int -&gt; Int -&gt; Int -&gt; Int -&gt; HDC -&gt; Int -&gt; Int -&gt; Int -&gt; Int -&gt; BLENDFUNCTION -&gt; IO BOOL
-}</span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="hs-identifier">WINDOWS_CCONV</span><span> </span><span class="hs-keyword">unsafe</span><span> </span><span class="hs-string">&quot;windows.h TransparentBlt&quot;</span><span>
</span><span id="line-41"></span><span>  </span><span class="hs-identifier">c_TransparentBlt</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">HDC</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">HDC</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">Int</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">UINT</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">IO</span><span> </span><span class="hs-identifier">BOOL</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-identifier">aC_SRC_OVER</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-44"></span><span class="hs-identifier">aC_SRC_OVER</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">0</span><span>
</span><span id="line-45"></span><span class="hs-pragma">{-# LINE 45 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-identifier">aC_SRC_ALPHA</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-47"></span><span class="hs-identifier">aC_SRC_ALPHA</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">1</span><span>
</span><span id="line-48"></span><span class="hs-pragma">{-# LINE 48 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">PBLENDFUNCTION</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span>
</span><span id="line-50"></span><span class="hs-keyword">type</span><span> </span><span class="hs-identifier">LPBLENDFUNCTION</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Ptr</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span class="hs-keyword">data</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span>
</span><span id="line-53"></span><span>    </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">blendOp</span><span>     </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-54"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">blendFlags</span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-55"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">sourceConstantAlpha</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-56"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="hs-identifier">alphaFormat</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">BYTE</span><span>
</span><span id="line-57"></span><span>    </span><span class="hs-special">}</span><span> </span><span class="hs-keyword">deriving</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">Show</span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-keyword">instance</span><span> </span><span class="hs-identifier">Storable</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-60"></span><span>    </span><span class="hs-identifier">sizeOf</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">const</span><span> </span><span class="hs-special">(</span><span class="hs-number">4</span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-pragma">{-# LINE 61 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-61"></span><span>    </span><span class="hs-identifier">alignment</span><span> </span><span class="hs-identifier">_</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-number">1</span><span>
</span><span id="line-62"></span><span class="hs-pragma">{-# LINE 62 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-62"></span><span>    </span><span class="hs-identifier">poke</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-identifier">func</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-63"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span>     </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">blendOp</span><span> </span><span class="hs-identifier">func</span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span class="hs-pragma">{-# LINE 64 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-64"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">1</span><span class="hs-special">)</span><span class="hs-special">)</span><span>  </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">blendFlags</span><span> </span><span class="hs-identifier">func</span><span class="hs-special">)</span><span>
</span><span id="line-65"></span><span class="hs-pragma">{-# LINE 65 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-65"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">sourceConstantAlpha</span><span> </span><span class="hs-identifier">func</span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span class="hs-pragma">{-# LINE 66 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-66"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">pokeByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">3</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">alphaFormat</span><span> </span><span class="hs-identifier">func</span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span class="hs-pragma">{-# LINE 67 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-67"></span><span>
</span><span id="line-68"></span><span>    </span><span class="hs-identifier">peek</span><span> </span><span class="hs-identifier">buf</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-69"></span><span>        </span><span class="hs-identifier">blendOp'</span><span>     </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">0</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span>
</span><span id="line-70"></span><span class="hs-pragma">{-# LINE 70 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-70"></span><span>        </span><span class="hs-identifier">blendFlags'</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">1</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span>
</span><span id="line-71"></span><span class="hs-pragma">{-# LINE 71 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-71"></span><span>        </span><span class="hs-identifier">sourceConstantAlpha'</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-72"></span><span>            </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">2</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span>
</span><span id="line-73"></span><span class="hs-pragma">{-# LINE 73 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-73"></span><span>        </span><span class="hs-identifier">alphaFormat'</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">peekByteOff</span><span> </span><span class="hs-identifier">hsc_ptr</span><span> </span><span class="hs-number">3</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">buf</span><span>
</span><span id="line-74"></span><span class="hs-pragma">{-# LINE 74 &quot;libraries\\Win32\\Graphics\\Win32\\GDI\\AlphaBlend.hsc&quot; #-}</span><span>
</span><span id="line-74"></span><span>        </span><span class="hs-identifier">return</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-identifier">BLENDFUNCTION</span><span> </span><span class="hs-identifier">blendOp'</span><span> </span><span class="hs-identifier">blendFlags'</span><span> </span><span class="hs-identifier">sourceConstantAlpha'</span><span> </span><span class="hs-identifier">alphaFormat'</span><span>
</span><span id="line-75"></span></pre></body></html>